<template>
    <div>
        <h1>子组件</h1>
        <h1>{{info}}</h1>
        <h1>{{$attrs.msg}}</h1>
        <GrandSon :message="message"></GrandSon>
    </div>
</template>

<script lang="ts">
import { defineComponent , onBeforeMount, onBeforeUnmount, onBeforeUpdate, onMounted, onUnmounted, onUpdated,ref} from 'vue'
import GrandSon from'./GrandSon.vue';
export default defineComponent({
    setup (props,context) {
        onBeforeMount(()=>{
            console.log('子元素的onBeforeMount')
        });
        onMounted(()=>{
            console.log('子元素的onMounted')
        });
        onBeforeUpdate(()=>{
            console.log('子元素的onBeforeUpdate')
        });
        onUpdated(()=>{
            console.log('子元素的onUpdated')
        });
        onBeforeUnmount(()=>{
            console.log('子元素的onBeforeUnmount')
        });
        onUnmounted(()=>{
            console.log('子元素的onUnmounted')
        });
        console.log(props);
        console.log(context);
        console.log(context.attrs);
        context.emit('fun','emit子组件传递过来的参数');
        let message = ref('父传子props传值');
        return {
            message
        }
    },
    props:{
        info:{
            type:String,
            required:true,
            default:'XXX'
        },
        obj:{
            type:Object,
            required:true,
            default:()=>{
                return{};//引用数据类型的默认值需要写成函数形式 默认值为return后面的值
            }
        }
    },
    emits:['fun'],
    components:{
        GrandSon
    }
})
</script>

<style scoped>

</style>